package com.ayoka.mvp;

import android.app.Activity;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.ayoka.R;
import com.ayoka.base.BasePresenter;
import com.ayoka.base.IBaseView;
import com.ayoka.mvp.BespokeCoachMVP.BespokeCoachModel.BespokeCoachBean;
import com.ayoka.utils.MediaManager;
import com.jcp.baselibrary.dialog.DialogHelper;
import com.jcp.baselibrary.utils.MyLogger;
import com.jcp.baselibrary.utils.UIUtils;
import com.ldf.calendar.model.CalendarDate;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by gabriel on 2017/3/5.
 */

public interface BespokeCoachMVP {

    interface  BespokeCoachModel {

        class BespokeCoachBean{

        }
    }

    interface IBespokeCoachView extends IBaseView {

        void configBespokeCoachData(BespokeCoachBean BespokeCoachBean);

        Activity getActivityView();

        CalendarDate getBespokeDate();

        void onBespokeSuccess(String date);

        void configBespokeCoachTimeListData(List<String> timeListData);
    }

    class BespokeCoachPresenter extends BasePresenter<IBespokeCoachView> {

        public void getTimeListData() {
            List<String> timeListData = new ArrayList<>();
            timeListData.add("上午 08:00");
            timeListData.add("上午 09:00");
            timeListData.add("上午 10:00");
            timeListData.add("上午 11:00");
            timeListData.add("上午 12:00");
            timeListData.add("下午 13:00");
            timeListData.add("下午 14:00");
            timeListData.add("下午 15:00");
            timeListData.add("下午 16:00");
            timeListData.add("下午 17:00");
            timeListData.add("下午 18:00");
            timeListData.add("下午 19:00");
            timeListData.add("下午 20:00");
            timeListData.add("下午 21:00");
            timeListData.add("下午 22:00");
            timeListData.add("下午 23:00");
            mViewRef.get().configBespokeCoachTimeListData(timeListData);
        }

        public void getBespokeCoachData(String date) {
            MyLogger.d(TAG, date);
            mViewRef.get().configBespokeCoachData(new BespokeCoachBean());
        }

        public void showConfirmBespokeDialog(final String time) {
            Activity activity = mViewRef.get().getActivityView();
            View confirmQuitView = LayoutInflater.from(activity).inflate(R.layout.dialog_confirm_tow_button, null);
            final AlertDialog dialog = DialogHelper.getDialog(activity).show();
            dialog.setContentView(confirmQuitView);
            TextView tvTitle = confirmQuitView.findViewById(R.id.tv_dialog_title);
            tvTitle.setText(R.string.point_out);
            TextView tvMessage = confirmQuitView.findViewById(R.id.tv_dialog_message);
            CalendarDate date = mViewRef.get().getBespokeDate();
            final String messageFormat = String.format(UIUtils.getString(R.string.confirm_bespoke_message), date.getMonth(), date.getDay(), time);
            tvMessage.setText(messageFormat);
            confirmQuitView.findViewById(R.id.btn_positive).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    submitBespoke(time);
                }
            });
            confirmQuitView.findViewById(R.id.btn_negative).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });
        }

        private void submitBespoke(String time) {
            CalendarDate date = mViewRef.get().getBespokeDate();
            mViewRef.get().onBespokeSuccess(date.toString());
        }

        private void showBespokeFailureDialog() {
            Activity activity = mViewRef.get().getActivityView();
            View confirmQuitView = LayoutInflater.from(activity).inflate(R.layout.dialog_confirm_one_button, null);
            final AlertDialog dialog = DialogHelper.getDialog(activity).show();
            dialog.setContentView(confirmQuitView);
            TextView tvTitle = confirmQuitView.findViewById(R.id.tv_dialog_title);
            tvTitle.setText(R.string.point_out);
            TextView tvMessage = confirmQuitView.findViewById(R.id.tv_dialog_message);
            tvMessage.setText(R.string.bespoke_again);
            Button btnConfirm = confirmQuitView.findViewById(R.id.btn_confirm);
            btnConfirm.setText(R.string.fine);
            btnConfirm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });
        }

    }

}
